<!DOCTYPE HTML>
<html>
<head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <link href="../static_pc/assets3/css/bs3/dpl-min.css" rel="stylesheet" type="text/css"/>
    <link href="../static_pc/assets3/css/bs3/bui-min.css" rel="stylesheet" type="text/css"/>
    <!-- <link href="../static_pc/assets/css/dpl-min.css" rel="stylesheet" type="text/css" />
    <link href="../static_pc/assets/css/bui-min.css" rel="stylesheet" type="text/css" /> -->
    <link href="../static_pc/assets/css/page-min.css" rel="stylesheet" type="text/css"/>
    <style type="text/css">
        [v-cloak] {
            display: none;
        }
    </style>
</head>
<body>
<div class="container">
    <div class="row">
        <form id="searchForm" class="form-horizontal span24">
            <div class="row">
                <div class="control-group span8">
                    <label class="control-label">关键字</label>
                    <input type="hidden" name="a">
                    <div class="controls">
                        <input type="text" class="control-text" name="key" placeholder="姓名/手机号/邀请码/二维码">
                    </div>
                </div>
                <div class="span3 offset">
                    <button type="button" id="btnSearch" class="button button-primary">搜索</button>
                </div>
            </div>
        </form>
    </div>
    <div class="search-grid-container">
        <div id="grid"></div>
    </div>

</div>

<script type="text/javascript" src="../static_pc/common/jquery.min-2.1.3.js"></script>
<script type="text/javascript" src="../static_pc/layer/layer.js"></script>
<script type="text/javascript" src="../static_pc/assets/js/bui.js"></script>
<script type="text/javascript" src="../static_pc/assets/js/config.js"></script>
<script type="text/javascript">
    BUI.use(['common/search', 'bui/overlay', 'common/page'], function (Search, Grid, Data, overlay) {
        var Grid = BUI.Grid,
            columns = [
                {title: '邀请码', dataIndex: 'inviteCode', elCls: 'center'},
                {title: '报名号', dataIndex: 'regNumber', elCls: 'center'},
                {title: '姓名', dataIndex: 'name', elCls: 'center'},
                {title: '券号', dataIndex: 'ticketNo', elCls: 'center'},
                {title: '性别', dataIndex: 'sex', elCls: 'center', renderer: function (value, obj) {
                        var sexStr = obj.sex==1?"男":"女";
                        return sexStr;
                    }
                },
                {title: '手机号', dataIndex: 'mobile', elCls: 'center'},
                {title: '公司', dataIndex: 'company', elCls: 'center'},
                {title: '职位', dataIndex: 'position', elCls: 'center'},
                {title: '证件号', dataIndex: 'credentialNo', elCls: 'center'},
                {title: '证件类型', dataIndex: 'credentialType', elCls: 'center'},
                {title: '邮箱', dataIndex: 'email', elCls: 'center'},
                {title: '上车点', dataIndex: 'aboardPoint', elCls: 'center'},
                {title: '是否单间', dataIndex: 'isSingle', elCls: 'center', renderer: function (value, obj) {
                    var isSingleStr = "";
                    if (obj.isSingle==1){
                        isSingleStr = "是";
                    }else if (obj.isSingle==0){
                        isSingleStr = "否";
                    }else {
                        isSingleStr = "";
                    }
                    return isSingleStr;
                }
                },
                {title: '发票抬头', dataIndex: 'invoice', elCls: 'center'},
                {title: '税号', dataIndex: 'dutyParagraph', elCls: 'center'},
                {title: '分论坛', dataIndex: 'forumNum', elCls: 'center', renderer: function (value, obj) {
                        var forumNumStr = "";
                        if (obj.forumNum==1){
                            forumNumStr = "中国智造，领航全球";
                        }else if (obj.forumNum==2){
                            forumNumStr = "电商新视界";
                        }else if (obj.forumNum==3){
                            forumNumStr = "玩转采购节";
                        }
                        return forumNumStr;
                    }
                },
                {title: '二维码号', dataIndex: 'qrcode', elCls: 'center', renderer: function (value, obj) {
                        var qrcodeStr = obj.qrcode;
                        return qrcodeStr;
                    }
                },
                {title: '是否签到', dataIndex: 'signCount', elCls: 'center', renderer: function (value, obj) {
                        var signinStr = obj.signCount>0?"已签到":"未签到";
                        return signinStr;
                    }
                },
                {title: '报名状态', dataIndex: 'regFlag', elCls: 'center', renderer: function (value, obj) {
                        var regFlagStr = obj.regFlag==1?"已报名":"未报名";
                        return regFlagStr;
                    }
                },
                {title: '问卷状态', dataIndex: 'quesCount', elCls: 'center', renderer: function (value, obj) {
                        var userQuesStr = obj.quesCount==1?"已作答":"未作答";
                        if (obj.quesCount==1){
                            var userQuesStrLink =  Search.createLink({ //链接使用 此方式
                                id : 'userQues' + obj.id,
                                title : '用户问卷记录',
                                text : userQuesStr,
                                href : 'userQuestion.html?user_id='+obj.id+'&act_id=1'
                            })
                            return userQuesStrLink;
                        }else {
                            return userQuesStr;
                        }
                    }
                },
                /*{
                    title: '操作', dataIndex: '', elCls: 'center', renderer: function (value, obj) {
                    var delStr = '<span class="grid-command btn-del" title="删除">删除</span>';
                    return delStr;
                }
                }*/
            ],
            store = Search.createStore('../api/userManage/loadList', {
                proxy: {
                    save: { //也可以是一个字符串，那么增删改，都会往那么路径提交数据，同时附加参数saveType
                        /* addUrl : '${pageContext.request.contextPath}/admin/addAdm.shtml',
                         updateUrl : '${pageContext.request.contextPath}/admin/updAdm.shtml',
                         removeUrl : '${pageContext.request.contextPath}/admin/delAdm.shtml' */
                    },
                    method: 'POST'
                },
                params: {
                    //配置初始请求的参数
                    id:1,
                },
                pageIndex: 0,
                pageSize: 10,
                autoSync: true //保存数据后，自动更新
            });

        var gridCfg = Search.createGridCfg(columns, {
            forceFit: true,
            emptyDataTpl: '<div class="centered"><img alt="Crying" src="http://img03.taobaocdn.com/tps/i3/T1amCdXhXqXXXXXXXX-60-67.png"><h2>查询的数据不存在</h2></div>',
            tbar: {
                items: [
                    {text: '<i class="icon-ok-sign"></i>手工签到', btnCls: 'button button-small', handler: signInFunction},
                    {text: '<i class="icon-remove"></i>删除', btnCls: 'button button-small', handler: delFunction},
                    {text: '<i class="icon-download"></i>导出用户记录', btnCls: 'button button-small', handler: downloadUserFunction},
                    {text: '<i class="icon-download"></i>导出问卷记录', btnCls: 'button button-small', handler: downloadUserQuesFunction},
                    {text: '<i class="icon-download"></i>导出问卷项人数统计', btnCls: 'button button-small', handler: downloadQuesCountFunction},
                ]
            },
            loadMask: true, //加载数据时显示屏蔽层
            plugins: [BUI.Grid.Plugins.CheckSelection] // 插件形式引入多选表格
        });

        var search = new Search({
                store: store,
                gridCfg: gridCfg
            }),
            grid = search.get('grid');

        function signInFunction() {
            var selections = grid.getSelection();
            var ids = [];
            BUI.each(selections, function (item) {
                ids.push(item.id);
            });
            if (ids.length) {
                BUI.Message.Confirm('确认要签到选中的记录么？', function () {
                    layer.load();
                    $.ajax({
                        url: "../api/userManage/updateUserSignin",
                        data: {"ids": ids.toString(),"actId":1},
                        dataType: "json",
                        type: "post",
                        async: true,
                        success: function (data) {
                            layer.closeAll('loading');
                            if (!data.hasError) {
                                store.load();
                            } else {
                                BUI.Message.Alert(data.error, 'warning');
                            }
                        },
                        error: function (XMLHttpRequest, textStatus, errorThrown) {
                            layer.closeAll('loading');
                            BUI.Message.Alert("系统繁忙，请稍后" + XMLHttpRequest.status + "," + XMLHttpRequest.readyState + "," + textStatus, 'warning');
                        }
                    });
                }, 'question');
            } else {
                BUI.Message.Alert("请选择记录", function () {
                }, 'warning');
            }
        }
        
        //删除操作
        function delFunction() {
            var selections = grid.getSelection();
            //alert(JSON.stringify(selections));
            delItems(selections);
        }

        function delItems(items) {
            var ids = [];
            BUI.each(items, function (item) {
                ids.push(item.id);
            });
            if (ids.length) {
                BUI.Message.Confirm('确认要删除选中的记录么？', function () {
                    layer.load();
                    $.ajax({
                        url: "../api/userManage/removeUserInfo",
                        data: {"ids": ids.toString()},
                        dataType: "json",
                        type: "post",
                        async: true,
                        success: function (data) {
                            layer.closeAll('loading');
                            if (!data.hasError) {
                                store.load();
                            } else {
                                BUI.Message.Alert(data.error, 'warning');
                            }
                        },
                        error: function (XMLHttpRequest, textStatus, errorThrown) {
                            layer.closeAll('loading');
                            BUI.Message.Alert("系统繁忙，请稍后" + XMLHttpRequest.status + "," + XMLHttpRequest.readyState + "," + textStatus, 'warning');
                        }
                    });
                }, 'question');
            } else {
                BUI.Message.Alert("请选择记录", function () {
                }, 'warning');
            }
        }
        
        function downloadUserFunction() {
            var downloadUserForm = "<form id='downUser' action='/api/outExcel/outUserInfo' method='post'>" +
                "<input name='delFlag' type='hidden' value='1'><input name='actId' type='hidden' value='1'></form>";
            $("body").append(downloadUserForm);
            $("#downUser").submit();
            $("#downUser").remove();
        }

        function downloadUserQuesFunction() {
            var downloadUserQuesForm = "<form id='downUserQues' action='/api/outExcel/outUserQues' method='post'>" +
                "<input name='delFlag' type='hidden' value='1'><input name='actId' type='hidden' value='1'><input name='regFlag' type='hidden' value='1'></form>";
            $("body").append(downloadUserQuesForm);
            $("#downUserQues").submit();
            $("#downUserQues").remove();
        }

        function downloadQuesCountFunction() {
            var downloadQuesCountForm = "<form id='downQuesCount' action='/api/outExcel/outQuesCount' method='post'>" +
                "<input name='delFlag' type='hidden' value='1'><input name='actId' type='hidden' value='1'></form>";
            $("body").append(downloadQuesCountForm);
            $("#downQuesCount").submit();
            $("#downQuesCount").remove();
        }

        //监听事件，删除一条记录
        grid.on('cellclick', function (ev) {
            var sender = $(ev.domTarget); //点击的Dom
            if (sender.hasClass('btn-del')) {
                var record = ev.record;
                delItems([record]);
            }
        });
    });
</script>

</body>
</html>  